<?php
require_once("projectView.php");
require_once(CORE_DIR.'projectModel.php');
require_once(CORE_DIR.'permissionModel.php');

class updateAction extends authAction{

	function __construct(){
		$this->view = new projectView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$pModel = new projectModel();		
		$permModel = new permissionModel();		
		
		if (isset($get["title"]) && isset($get["id"]) ){
			$id = $get["id"];
			$prjName = $get["title"];
			$projectOrderList = explode("|", $get["projectidlist"]);
				
			$status = 0;
			if ($pModel->updateProject($id, $prjName, $projectOrderList)){
				$status = 1;
			}	

			if (isset($get["useridlist"]))
			{
				$permModel->deleteProjectPermissions($id);
				$permModel->addPermissionsToProj($id, $get["useridlist"]);
			}
			
			$this->view->setProperty("status", $status);
			$this->view->setProperty("id", $id);
			$this->view->showUpdateProject();
		}
		else if(isset($get["archive"]) && isset($get["id"]) ){
			$id = $get["id"];
			$archState = $get["archive"];

			$status = 0;
			if ($pModel->updateProjectArchState($id, $archState)){
				$status = 1;
			}	
			$this->view->setProperty("status", $status);
			$this->view->setProperty("id", $id);
			$this->view->showUpdateProject();
		}
		else{
			$this->view->showBadCmd();
		}	
			
	}
}
?>